package com.zyf.wjy.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.zyf.wjy.entity.SystemLog;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 系统日志DAO
 */
@Repository
public class SystemLogDao extends BaseDao<SystemLog> {
    
    @Override
    protected String getFileName() {
        return "system_logs.json";
    }
    
    @Override
    protected TypeReference<List<SystemLog>> getTypeReference() {
        return new TypeReference<List<SystemLog>>() {};
    }
    
    @Override
    protected Long getId(SystemLog entity) {
        return entity.getId();
    }
    
    @Override
    protected void setId(SystemLog entity, Long id) {
        entity.setId(id);
    }
    
    /**
     * 根据用户名查询
     */
    public List<SystemLog> findByUsername(String username) {
        return findAll().stream()
            .filter(log -> username.equals(log.getUsername()))
            .toList();
    }
    
    /**
     * 根据操作类型查询
     */
    public List<SystemLog> findByOperationType(String operationType) {
        return findAll().stream()
            .filter(log -> operationType.equals(log.getOperationType()))
            .toList();
    }
}

